<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../../plugins/element-ui/index.css" />
    <link rel="stylesheet" href="../../styles/common.css" />
    <link rel="stylesheet" href="../../styles/page.css" />
    <style>
        #member-app  .notAdmin::after {
            border: 0 !important;
        }
        .search-btn {
            margin-left: 20px;
        }
        .tableBar{
            justify-content: flex-start !important;
        }
        .info-box{
            margin: -15px -44px 20px;
        }
        .info-box .item-box{
            display: flex;
            height: 20px;
            line-height: 20px;
            font-size: 14px;
            font-weight: 400;
            color: #666666;
            text-align: left;
            margin-bottom: 14px;
        }
        .info-box .item-box:last-child{
            margin-bottom: 0;
        }
        .info-box .item-box .label{
            width: 96px;
        }
        .info-box .item-box .des{
            flex: 1;
            color: #333333;
        }
    </style>
</head>
<body>
<div class="dashboard-container" id="member-app">
    <div class="container">
        <div class="tableBar">

            <el-input
                    v-model="inputName"
                    placeholder="请输入商品名称"
                    style="width: 250px"
                    clearable
                    @keyup.enter.native="handleQuery"
            >
                <i
                        slot="prefix"
                        class="el-input__icon el-icon-search"
                        style="cursor: pointer"
                        @click="handleQuery"
                ></i>
            </el-input>&nbsp;&nbsp;&nbsp;
            <el-select v-model="inputProvider" placeholder="请选择供应商" style="width: 250px">
                <el-option label="未选择供应商" value=""></el-option>
                <el-option v-for="pid in proname" :key="pid" :label="pid.toString()" :value="pid" >
                </el-option>
            </el-select>&nbsp;&nbsp;&nbsp;
            <el-select v-model="isPay" placeholder="请选择是否支付" style="width: 200px" @click="handleQuery">
                <el-option label="未选择付款状态" value=""></el-option>
                <el-option label="已支付" value="1"></el-option>
                <el-option label="未支付" value="0"></el-option>
            </el-select>
            <el-button type="primary" class="search-btn" @click="handleQuery">查询</el-button>

            <el-button
                    type="primary"
                    @click="addBillHandle('add')"
            >
                + 添加订单
            </el-button>
        </div>
        <el-table
                :data="tableData"
                stripe
                class="tableBox"
        >
            <el-table-column
                    prop="billcode"
                    label="订单编码"
            ></el-table-column>

            <el-table-column
                    prop="productname"
                    label="商品名称"
            ></el-table-column>
            <el-table-column prop="proname" label="供应商">
                <template slot-scope="scope">
                    {{ scope.row.proname }}
                </template>
            </el-table-column>
            <el-table-column
                    prop="totalprice"
                    label="商品总额"
            ></el-table-column>
            <el-table-column
                    prop="ispayment"
                    label="是否付款"
            >
                <template slot-scope="scope">
                    <span style="margin-right: 10px;">{{ scope.row.ispayment == '0' ? '未支付' : '已支付' }}</span>
                </template>
            </el-table-column>
            <el-table-column
                    prop="creationdate"
                    label="创建时间"
            ></el-table-column>
            <el-table-column
                    label="操作"
                    width="160"
                    align="center"
            >
                <template slot-scope="scope">
                    <el-button
                            type="text"
                            size="small"
                            class="blueBug"
                            @click="examineBillHandle(scope.row.id)"
                    >
                        查看
                    </el-button>
                    <el-button
                            type="text"
                            size="small"
                            class="blueBug"
                            @click="addBillHandle(scope.row.id)"
                    >
                        修改
                    </el-button>
                    <el-button
                            type="text"
                            size="small"
                            class="delBut non"
                            @click="deleteHandle(scope.row.id)"
                    >
                        删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
                class="pageList"
                :page-sizes="[10, 20, 30, 40]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="counts"
                :current-page.sync="page"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
        ></el-pagination>
    </div>
</div>
<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="../../plugins/vue/vue.js"></script>
<!-- 引入组件库 -->
<script src="../../plugins/element-ui/index.js"></script>
<!-- 引入axios -->
<script src="../../plugins/axios/axios.min.js"></script>
<script src="../../js/request.js"></script>
<script src="../../api/bill.js"></script>
<script>
    new Vue({
        el: '#member-app',
        data() {
            return {
                inputName:'',
                inputProvider: '',
                isPay:'',
                proname: [],
                counts: 0,
                page: 1,
                pageSize: 10,
                tableData : [],
                id : '',
                status : '',
            }
        },
        computed: {},
        created() {
            this.init()
            this.user = JSON.parse(localStorage.getItem('userInfo')).username
        },
        mounted() {
            this.getDistinctProname(); // 在mounted方法中调用方法
        },
        methods: {
            async init () {
                const params = {
                    page: this.page,
                    pageSize: this.pageSize,
                    name: this.inputName ? this.inputName : undefined,
                    provider: this.inputProvider ? this.inputProvider : undefined,
                    isPay: this.isPay ? this.isPay : undefined
                }
                await getBillList(params).then(async res => {
                    if (String(res.code) === '1') {
                        this.tableData = res.data.records || []
                        this.counts = res.data.total
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },
            handleQuery() {
                this.page = 1;
                this.init();
            },
            getDistinctProname () {
                return $axios({
                    url: '/bill/all/proname',
                    method: 'get',
                }).then(response => {
                    if (response.data && response.data.length) {
                        // 赋值proname
                        this.proname = response.data;
                    }
                }).catch(error => {
                    console.error(error);
                });
            },
            // 添加
            addBillHandle (st) {
                if (st === 'add'){
                    window.parent.menuHandle({
                        id: '4',
                        url: '/backend/page/bill/add.html',
                        name: '添加订单'
                    },true)
                } else {
                    window.parent.menuHandle({
                        id: '4',
                        url: '/backend/page/bill/add.html?id='+st,
                        name: '修改订单'
                    },true)
                }
            },
            //查看
            examineBillHandle (id) {
                window.parent.menuHandle({
                    id: '4',
                    url: '/backend/page/bill/details.html?id='+id,
                    name: '查看订单明细'
                },true)
            },
            //删除
            deleteHandle(id) {
                this.$confirm('此操作将永久删除, 是否继续?', '提示', {
                    'confirmButtonText': '确定',
                    'cancelButtonText': '取消',
                    'type': 'warning'
                }).then(() => {
                    deleBill(id).then(res => {
                        if (res.code === 1) {
                            this.$message.success('删除成功！')
                            this.handleQuery()
                        } else {
                            this.$message.error(res.msg || '操作失败')
                        }
                    }).catch(err => {
                        this.$message.error('请求出错了：' + err)
                    })
                })
            },
            handleSizeChange (val) {
                this.pageSize = val
                this.init()
            },
            handleCurrentChange (val) {
                this.page = val
                this.init()
            }
        }
    })
</script>
</body>
</html>